import base64
import pickle
import re


def pickle_dumps_to_str(obj):
    try:
        s = base64.encodebytes(pickle.dumps(obj)).decode()
        f = open('db.obj','w')
        f.write(s)
        f.close()
        return True
    except pickle.PicklingError:
        print('转化str失败')
        return False
def pickle_loads_from_str():
    try:
        f = open('db.obj','r')
        s = f.read()
        print('从文件读取的序列化对象')
        print(s)
        return pickle.loads(base64.decodebytes(s.encode()))
    except pickle.UnpicklingError as e:
        print(e)
        print('转化obj 失败')
        pass
# '''按照指定长度分割'''
# def cutText(text, sec):
#     list_i = list(text)    # str -> list
#     for i,v in enumerate(list_i):
#         if i % sec == 0:
#             list_i.insert(i, ' ')   # 注意不用重新赋值
#     str_i = ''.join(list_i)    # list -> str
#     return str_i
